import { MoveInfo, TButton, TLayout } from "../SceneControl";
import MainPageScene from "./MainPageScene";

const { ccclass, property } = cc._decorator;

@ccclass
export default class ActivityPanelViewScene extends MainPageScene {

    @property(cc.ScrollView)
    scroll: cc.ScrollView = null;

    getUpLayout(): TLayout {
        let layout = new TLayout();
        layout.buttonList = this.btns;
        return layout;
    }

    public initScene(): void {
        super.initScene();
        this.tscene.site.row = 0;
        this.tscene.apply();
    }

    get btns(): TButton[][] {
        let btns = [this.scroll.content.children.map(item => new TButton(item.getChildByName("btnBattle")))];
        btns[0].forEach(item => {
            item.addBeforeFingerInEvent(this.fingerIn.bind(this));
        });
        return btns;
    }

    fingerIn(mi: MoveInfo) {
        this.scroll.scrollToPercentHorizontal(mi.targetLayout.site.line / (mi.targetLayout.buttonList[0].length - 1), 0.2); 
    }

} 
